﻿using EnvDTE;
using Sasa.QualityTools.CodeAnalysis.Core.VisualStudio;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.VisualStudio
{
    public class VisualBasicCodeModel : CodeModel
    {
        internal VisualBasicCodeModel(FileCodeModel model)
            : base(model)
        {
        }


        protected override string ConvertToClrTypeName(string typeName)
        {
            var clrTypeName = new StringBuilder();

            var counter = 0;
            var isGenericTypeParameter = false;
            foreach (var ch in typeName)
            {
                switch (ch)
                {
                    case '(':
                        isGenericTypeParameter = true;
                        counter = 1;
                        clrTypeName.Append('`');
                        break;
                    case ')':
                        isGenericTypeParameter = false;
                        clrTypeName.Append(counter);
                        break;
                    case ',':
                        counter++;
                        break;
                    default:
                        if (!isGenericTypeParameter)
                        {
                            clrTypeName.Append(ch);
                        }
                        break;
                }
            }

            return clrTypeName.ToString();
        }
    }
}
